package per.hx.bs.util;

import per.hx.bs.constant.Global;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author HuXing
 * @date 2018/3/23  14:14
 * 查询参数
 */
public class Query extends LinkedHashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    private int offset;
    /**
     * 每页条数
     */
    private int limit;

    public Query(Map<String, Object> params) {
        this.putAll(params);
        // 分页参数
        if (null != params.get(Global.OFFSET)) {
            this.offset = Integer.parseInt(params.get(Global.OFFSET).toString());
        } else {
            this.offset = 0;
        }
        if (null != params.get(Global.LIMIT)) {
            this.limit = Integer.parseInt(params.get(Global.LIMIT).toString());
        } else {
            this.limit = 10;
        }
        this.put("offset", offset);
        this.put("page", offset / limit + 1);
        this.put("limit", limit);
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.put("offset", offset);
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

}
